import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
  OneToMany,
} from 'typeorm';
import { User } from '../../users/entities/user.entity';
import { Task } from './task.entity';
import { TaskCategory } from './task-category.entity';

@Entity('task_templates')
export class TaskTemplate {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ length: 128 })
  title: string;

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({ name: 'task_category_id' })
  taskCategoryId: string;

  @ManyToOne(() => TaskCategory, (category) => category.taskTemplates, {
    createForeignKeyConstraints: false,
  })
  @JoinColumn({ name: 'task_category_id' })
  taskCategory: TaskCategory;

  @Column({ default: 1 })
  version: number;

  @Column({ name: 'created_by' })
  createdBy: string;

  @ManyToOne(() => User, { createForeignKeyConstraints: false })
  @JoinColumn({ name: 'created_by' })
  creator: User;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;

  @Column({ name: 'is_deleted', default: false })
  isDeleted: boolean;

  @OneToMany(() => Task, (task) => task.taskTemplate)
  tasks: Task[];
}
